<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="quo" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="offerUpSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/crm/sale/OfferDetMes?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 添加新报价 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="主题" prop="quo_theme">
                  <el-input v-model="quo.quo_theme" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="客户" prop="client">
                  {{quo.client}}
                  <el-button @click="popSelectCustomersSale('client','quo_client')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="联系人" prop="contact">
                  {{quo.contact}}
                  <el-button @click="popChooseContacts('contact','quo_contact')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="内部备注" prop="quo_insides">
                  <el-input type="textarea" v-model="quo.quo_insides" ttparea=350></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-button @click="offerUpSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/crm/sale/OfferDetMes?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'产品报价'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="SelectCustomersSaleVisible" append-to-body>
      <SelectCustomersSale v-if="SelectCustomersSaleVisible" ref="SelectCustomersSale" :popparams="popparams"> </SelectCustomersSale>
    </el-dialog>
    <el-dialog :visible.sync="ChooseContactsVisible" append-to-body>
      <ChooseContacts v-if="ChooseContactsVisible" ref="ChooseContacts" :popparams="popparams"> </ChooseContacts>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SelectCustomersSale from "@/views/crm/sale/contract/SelectCustomersSale";
  import ChooseContacts from "@/views/crm/sale/contract/ChooseContacts";
  export default {
    name: 'OfferUp',
    components: {
      SelectCustomersSale,
      ChooseContacts,
    },
    props: ['popparams'],
    data() {
      return {
        SelectCustomersSaleVisible: false,
        SelectCustomersSaleValue: null,
        SelectCustomersSaleDesc: null,
        ChooseContactsVisible: false,
        ChooseContactsValue: null,
        ChooseContactsDesc: null,
        vueparams: this.getVUEParams(""),
        quo: {
          quo_theme: null,
          client: null,
          contact: null,
          quo_insides: null,
        },
        loading: false,
        Container: null,
        rules: {
          quo_theme: [{
            required: true,
            message: "主题不能为空",
            trigger: 'blur',
          }],
          client: [{
            required: true,
            message: "客户不能为空",
            trigger: 'change',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "80299289AF2443B18EA545A4C0C37170",
        name: "客户管理右菜单",
        selected: "产品报价"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/OfferDetMes/offerUp?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      offerUpSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/OfferDetMes/offerUpSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/OfferDetMes/offerDetMes?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSelectCustomersSale(desc, value) {
        this.SelectCustomersSaleVisible = true;
        this.SelectCustomersSaleDesc = desc;
        this.SelectCustomersSaleValue = value;
      },
      closeSelectCustomersSale(value, desc) {
        this.SelectCustomersSaleVisible = false;
        this.$set(this.quo, this.SelectCustomersSaleDesc, desc);
        this.$set(this.quo, this.SelectCustomersSaleValue, value);
      },
      popChooseContacts(desc, value) {
        this.ChooseContactsVisible = true;
        this.ChooseContactsDesc = desc;
        this.ChooseContactsValue = value;
      },
      closeChooseContacts(value, desc) {
        this.ChooseContactsVisible = false;
        this.$set(this.quo, this.ChooseContactsDesc, desc);
        this.$set(this.quo, this.ChooseContactsValue, value);
      },
    },
  }
</script>
